package xine.demo.ssm.dao.impl;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class MapMapper implements RowMapper<Map<String,Object>> {
    @Override
    public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
        //System.out.println(rowNum); //表示第几行数据

        ResultSetMetaData metaData = rs.getMetaData();
        Map<String, Object> map = new HashMap<>();
        for (int columnIndex = 1, len = metaData.getColumnCount(); columnIndex <= len; columnIndex++) {
            String columnName = metaData.getColumnName(columnIndex);
            //System.out.println("name : " + columnName);
            map.put(columnName, rs.getObject(columnIndex));
        }
        return map;
    }
}
